package cn.tramy.pinxian.wind.command


import cn.tramy.pinxian.wind.command.annotation.CommandHandler
import cn.tramy.pinxian.wind.command.dispatch.CommandDispatcher
import cn.tramy.pinxian.wind.eventstore.DefaultEventStore
import cn.tramy.pinxian.wind.eventstore.storage.MemEventStorage
import cn.tramy.pinxian.wind.handler.registry.DefaultHandlerRegistry
import org.junit.jupiter.api.BeforeEach

internal class DefaultCommandBusTest {

    private lateinit var commandBus: CommandBus
    private val handlerRegistry = DefaultHandlerRegistry()
    private val eventStorage = MemEventStorage()
    private val eventStore = DefaultEventStore(eventStorage)
    private val commandDispatcher = CommandDispatcher(handlerRegistry)
    @BeforeEach
    fun setUp() {
        this.commandBus = DefaultCommandBus(commandDispatcher)
        this.handlerRegistry.registerHandler(TestCommandHandler(), CommandHandler::class.java)
    }

    @org.junit.jupiter.api.Test
    fun send() {
        this.commandBus.send(TestCommand())
    }
}

class TestCommand

class TestCommandHandler {
    @CommandHandler
    fun process(command: TestCommand) {
        println("process command: $command")
    }
}